import React, { Component } from 'react';
import { Input, Select, Button, Form, Alert, Space } from 'antd';
import { Link, Route, BrowserRouter } from 'react-router-dom';
import service from '../../utils/service';
import { render } from '@testing-library/react';

const { Option } = Select;
const { TextArea } = Input;


class reportDangers extends Component<any, any> {
    constructor(props: any) {
        super(props)
    }
    generateRandomSixDigits(): number {
        const min = 100000; // 最小值为 100000，保证生成的是六位数
        const max = 999999; // 最大值为 999999，保证生成的是六位数
        return Math.floor(Math.random() * (max - min + 1) + min);
    }




    sub = (values: any): void => {
        //已完成的提交到待验证
        if (values.status === '1') {
            console.log(this.generateRandomSixDigits());

            service({
                url: "http://localhost:3000/yanhengList",
                method: 'post',
                data: {
                    id: this.generateRandomSixDigits(),
                    ...values
                }
            }).then(res => {
                console.log(111);
                <Alert message="Success Text" type="success" />
                this.props.history.push("/Main/dangerManagement")
            })
            //未处理的提交到待审核
        } else if (values.status === '2') {
            service({
                url: "http://localhost:3000/shenheList",
                method: 'post',
                data: {
                    id: this.generateRandomSixDigits(),
                    ...values
                }
            }).then(res => {
                <Alert message="Success Tips" type="success" showIcon />
                this.props.history.push("/Main/dangerManagement")



            })
        }
    }
    render() {
        return (
            <div>
                <Form
                    labelCol={{ span: 4 }}
                    wrapperCol={{ span: 14 }}
                    layout="horizontal"
                    style={{ maxWidth: 600 }}
                    onFinish={this.sub}
                >


                    <div style={{ borderBottom: '3px solid #999', height: '30px', lineHeight: '30px', fontWeight: 'bolder' }}>
                        上报隐患
                    </div>
                    <div style={{ display: 'flex', alignItems: 'center', marginTop: '20px' }}>
                        <Form.Item label="隐患名称:" name='name' >
                            <Input placeholder="隐患名称" style={{ width: '500px' }} />
                        </Form.Item>
                    </div>
                    <div style={{ display: 'flex', alignItems: 'center', marginTop: '20px' }}>
                        <Form.Item label="上报人:" name='name1' >
                            <Input placeholder="上报人" style={{ width: '500px' }} />
                        </Form.Item>
                    </div>
                    <div style={{ display: 'flex', alignItems: 'center', marginTop: '20px' }}>
                        <Form.Item label="隐患类型:" name='type'>
                            <Select defaultValue="隐患类型" style={{ width: '500px' }}>
                                <Option value="校园三防建设">校园三防建设</Option>
                                <Option value="校园食品卫生">校园食品卫生</Option>
                                <Option value="校园消防安全">校园消防安全</Option>
                                <Option value="体艺设施设备">体艺设施设备</Option>
                            </Select>
                        </Form.Item>
                    </div>
                    <div style={{ display: 'flex', alignItems: 'center', marginTop: '20px' }}>
                        <Form.Item label=" 隐患地点:" name='address'>
                            <Input placeholder="隐患地点" style={{ width: '500px' }} />
                        </Form.Item>
                    </div>
                    <div style={{ display: 'flex', alignItems: 'center', marginTop: '20px' }}>
                        <Form.Item label=" 上报时间:" name='time'>
                            <Input placeholder="请填写上报时间" style={{ width: '500px' }} />
                        </Form.Item>
                    </div>
                    <div style={{ display: 'flex', alignItems: 'center', marginTop: '20px' }}>
                        <>
                            <Form.Item label=" 隐患描述: " name='desc'>
                                <TextArea rows={4} style={{ width: '500px' }} />
                            </Form.Item>
                        </>
                    </div>


                    <div style={{ display: 'flex', alignItems: 'center', marginTop: '20px' }}>
                        <Form.Item label="是否处理:" name='status' >
                            <Select defaultValue="处理状态" style={{ width: '500px' }}>
                                <Option value="1">已处理</Option>
                                <Option value="2">未处理</Option>
                            </Select>
                        </Form.Item>
                    </div>
                    <div>
                        <Button type="primary" htmlType="submit" style={{ marginTop: '20px', marginLeft: '60px', marginRight: '20px' }}>确定</Button>
                        <Button> <Link to="/Main/dangerManagement">取消</Link></Button>
                    </div>
                </Form >
            </div >
        );
    }
}

export default reportDangers;